

function setCubeColor(temperature, tempmax, tempmin){
	
	var delta = tempmax-tempmin;
	
	var valeurRouge = temperature/ delta;
	var valeurBleu =  1- (temperature/delta);
	
	var color = new THREE.Color( 0xff0000 );
	
	var i = color.getHex();
	color.setRGB(valeurRouge,0,valeurBleu);
	
	return color.getHex();
}

function createCube(temperature,posx,posy,posz,tempMax,tempMin,taille){
	
	var geometry = new THREE.CubeGeometry(taille,taille,taille);	
	
	var material = new THREE.MeshBasicMaterial({color:setCubeColor(temperature,tempMax,tempMin)}); 
	
	var cube = new THREE.Mesh(geometry, material); 

	cube.position.x = 0.5 + posx;
	cube.position.y = 0.5 + posy;
	cube.position.z = 0.5 + posz;
	
	return cube;
}

function afficherGrille(scene,largeur,hauteur,pas){
	var size = largeur * hauteur;
	var step = pas;

	var geometry = new THREE.Geometry();

		for ( var i = - size; i <= size; i += step ) {

					geometry.vertices.push( new THREE.Vector3(- size , 0, i ) );
					geometry.vertices.push( new THREE.Vector3( size, 0, i ) );

					geometry.vertices.push( new THREE.Vector3( i, 0, - size ) );
					geometry.vertices.push( new THREE.Vector3( i, 0, size) );

				}
	var material = new THREE.LineBasicMaterial( { color: 0x000000, opacity: 0.2 } );

	var line = new THREE.Line( geometry, material );
	line.type = THREE.LinePieces;
	scene.add( line );

}

